package com.cloud.nio;

import java.nio.Buffer;
import java.nio.ByteBuffer;

public class ByteBufferPutGet {

    public static void main(String[] args) {
        // 创建一个buffer
        ByteBuffer buffer = ByteBuffer.allocate(64);

        // 类型化方式放入数据
        buffer.putInt(100);
        buffer.putLong(10l);
        buffer.putChar('c');
        buffer.putShort((short)4);

        // 取出
        buffer.flip();

        System.out.println();

        // 取出也需要按照顺序，且需要按照对应的类型取出，否则会报错且取出的数据有问题
        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getLong());
    }
}
